package com.contacts.taopiaopiao;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;

import com.contacts.paystander.PayInterfaceActivity;

/**
 * Created by zuo on 2018/3/29.
 */

public class BaseActivity extends Activity implements PayInterfaceActivity{

    protected Activity that;
    @Override
    public void attach(Activity proxyActivity) {
        that = proxyActivity;
    }

    @Override
    public void setContentView(View view) {
        if(that != null){
            that.setContentView(view);
        }else {
            super.setContentView(view);
        }
    }

    @Override
    public void setContentView(int layoutResID) {
        if(that != null){
            that.setContentView(layoutResID);
        }else {
            super.setContentView(layoutResID);
        }
    }

    @Override
    public <T extends View> T findViewById(int id) {
        if(that != null){
            return that.findViewById(id);
        }else {
            return super.findViewById(id);
        }
    }

    @Override
    public Intent getIntent() {
        if(that != null){
            return that.getIntent();
        }else {
            return super.getIntent();
        }
    }

    @Override
    public void startActivity(Intent intent) {
        //这里千万不要把清单文件中的ProxyActivity的launchMode设置为单例的，必须是standard的，
        // 不然不能跳转
        Intent m = new Intent();
        m.putExtra("className",intent.getComponent().getClassName());
        that.startActivity(m);
    }

    @Override
    public ComponentName startService(Intent service) {
        Intent m = new Intent();
        m.putExtra("serviceName",service.getComponent().getClassName());
        return that.startService(m);
    }

    @Override
    public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter) {
        return that.registerReceiver(receiver, filter);
    }

    @Override
    public void sendBroadcast(Intent intent) {
        that.sendBroadcast(intent);
    }

    @Override
    public ClassLoader getClassLoader() {
        return that.getClassLoader();
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
    }

    @Override
    public void onStart() {

    }

    @Override
    public void onResume() {
    }

    @Override
    public void onPause() {

    }

    @Override
    public void onStop() {

    }

    @Override
    public void onDestroy() {

    }

    @Override
    public void onSaveInstanceState(Bundle outState) {

    }
}
